define(function(require, exports, module) {
    "use strict";
    var $ = require("$");

    var async = function(u, c, t, g, d) {
    	var _img = '<img src="../images/loading.gif"/>',
		_mask = "",
		loadingObjArr = [],
		time = (new Date).getTime() + parseInt(Math.random() * 1e5);
		time && (_mask = "background:rgba(255, 255, 255, 0.6); filter:alpha(opacity=30); _background:#fff;");
		if(t.length){
			var load = '<div style="' + _mask + '" id="loadingBox_' + time + '" class="monkey-ajax-loading">' + _img + "</div>";

			$("body").append(load);

			loadingObjArr[time] = $("#loadingBox_" + time);
			var oImg = $(t),
			w = oImg.outerWidth(),
			h = oImg.outerHeight(),
			offsetT = oImg.offset().top,
			offsetTL = oImg.offset().left,
			f = $("#loadingBox_" + time),
			_l = 32;

			f.css({
				position: "absolute",
				"z-index": "10000",
				"text-align": "center",
				width: w + "px",
				height: h - (h / 2 - _l / 2) + "px",
				paddingTop: h / 2 - _l / 2 + "px",
				top: offsetT + "px",
				left: offsetTL + "px"
			})
		}

        $.ajax(u, {
            type: g || "post",
            data: d,
            dataType: "json"
        }).done(function(d) {
        	$(t).length && loadingObjArr[time] && loadingObjArr[time].remove();
            c && c(d);
        }).fail(function() {
           	$(t).length && loadingObjArr[time] && loadingObjArr[time].remove();
        });
    }
    return {
        get: function(u, c, t) {
            async(u, c, t, 'get')
        },
        post: function(u, c, t, g, d) {
            async(u, c, t, g, d)
        },
        postd: function(u, c, d) {
            async(u, c, false, false, d)
        }
    }
})